<template>
	<view class="wrap">
		<u-form class="form" ref="uForm" label-position="left" :model="model" :rules="rules">
			<u-form-item label="订单号" prop="id" label-width="180" style="font-weight: 800;">
				<view>1000000050#01</view>
			</u-form-item>
			<u-form-item label="机台" prop="id" label-width="180">
				<view></view>
			</u-form-item>
			<u-form-item label="工序编码" prop="id" label-width="180">
				<view>ZS</view>
			</u-form-item>
			<u-form-item label="工序名称" prop="id" label-width="180">
				<view>注塑</view>
			</u-form-item>
			<u-form-item label="存货编码" prop="id" label-width="180">
				<view>01.A003.05.0001</view>
			</u-form-item>
			<u-form-item label="加工数量" prop="iqty" label-width="180" style="color: red;font-weight: 800;" :required="true">
				<u-input placeholder="请输入" v-model="model.iqty" type="text" maxlength="64" :custom-style="customStyle"></u-input>
			</u-form-item>
			<u-form-item label="操作工" prop="operator" label-width="180" style="color: red;font-weight: 800;" :required="true">
				<u-input placeholder="请扫码" v-model="model.operator" type="text" maxlength="64" :operatorFocus="operatorFocus" :custom-style="customStyle"></u-input><u-icon @click="search" name="scan" size="60"></u-icon>
			</u-form-item>
			<u-form-item label="计件单价" prop="id" label-width="180">
				<view>12.00</view>
			</u-form-item>
			<u-form-item label="报工人" prop="id" label-width="180">
				<view>system</view>
			</u-form-item>
			
		</u-form>
		<view class="btn-group cu-bar foot padding" ref="btn-group">
			<!-- round -->
			<button class="cu-btn  lines-red lg " @click="reset">重置</button>
			<button class="cu-btn  bg-confirm lg margin-left " @click="confirm">确定</button>
		
		</view>
	</view>
</template>

<script>
	import { plus } from '@dcloudio/uni-app-plus'
	export default {
		data() {
			return {
				model: {
					iqty:10,
					operator:''
				},
				rules: {
					operator: [
						{
							required: true,
							message: '请扫码操作工',
							trigger: ['change','blur'],
						}
					]
				},
				customStyle:{
					color:'red'
				},
				operatorFocus:true
			}
		},
		onBackPress(event){
			console.log(event,'event')
            uni.reLaunch({
                url:'/pages/mes/index/index'
            });
           return true;
        },

		onLoad() {
			// this.backPressHandler = () => {
			// // 在这里处理返回键逻辑，比如弹出确认框
			// console.log('返回键被点击');
			// // this.showConfirm();
			// // 返回true表示已处理该事件，阻止默认返回行为；返回false则不阻止
			// return true;
			// };
			// // 添加返回键监听
			// uni.addInterceptor('backPress', this.backPressHandler);
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods:{
			search(){
				this.operatorFocus = true
				this.$forceUpdate()
			},
			reset(){
				this.model = {}
			},    
			handleBackButtonClick() {
				console.log('返回键被点击')
				this.showConfirm()
			},
			confirm(){
				console.log(this.model,'model===')
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log(valid,'valid')
					} else {
						this.$u.toast('您填写的信息有误，请根据提示修正。');
					}
				});
			}
		}
	}
</script>

<style scoped>
	.bg-confirm {
	  background: #3e97b0;
	  color: #ffffff;
	}
</style>